package Assembler;

import java.io.FileNotFoundException;
import java.io.PrintStream;

public class AssemblerMain
{
    public static final int VERSION = 1;

    public static void main(String[] args)
    {
        AssemblerPassOne passOne = new AssemblerPassOne(args[0]);
        passOne.DisplayData();
        AssemblerPassTwo passTwo = new AssemblerPassTwo(passOne.Data, passOne.symTable);
        passTwo.Compute();
        if (!passOne.fatalError)
        {
            passTwo.SymbolTable.PrintTable();
            System.out.println("Object File");
            passTwo.ObjFile.PrintToFile(System.out);
            String filename = "output.txt";
            if (args.length > 1)
            {
                filename = args[1];
            }
            try
            {
                passTwo.ObjFile.PrintToFile(new PrintStream(filename));
            }
            catch (FileNotFoundException ex)
            {
                System.out.println("Unable to output to file: " + filename);
            }
        }

    }

}
